package com.mapperdb.scripting.xmltags;

import org.apache.ibatis.scripting.xmltags.DynamicContext;
import org.apache.ibatis.scripting.xmltags.SqlNode;

public class StrSqlNode implements SqlNode {
	// 在…前加上
	protected String prefix_text;
	// 在…后加上
	protected String suffix_text;
	protected SqlNode contents;

	/**
	 * contents + text
	 * @Title:StaticSqlNode
	 * @param contents
	 * @param text
	 */
	public StrSqlNode(SqlNode contents, String prefix_text, String suffix_text) {
		this.contents = contents;
		this.prefix_text = prefix_text;
		this.suffix_text = suffix_text;
	}

	@Override
	public boolean apply(DynamicContext context) {
		if (prefix_text != null) context.appendSql(prefix_text);
		contents.apply(context);
		if (suffix_text != null) context.appendSql(suffix_text);
		return true;
	}
}
